package com.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class UrlConnectionClient {
	public static void main(String[] args){
		//用法
		if(args.length<1){
			System.out.println("Usage: UrlConnectionClient <url>");
			return;
		}
		
		//解析URL
		URL url;
		try {
			url = new URL(args[0].trim());
			//连接
			URLConnection sock=url.openConnection();
			
			//读取并输出
			BufferedReader reader=new BufferedReader(new InputStreamReader(sock.getInputStream()));
			String next_record=null;
			while((next_record=reader.readLine())!=null){
				System.out.println(next_record);
			}
			reader.close();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e.getMessage());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e.getMessage());
		}
	}
}
